package com.czq.gulimail.gulimailproduct.controller;

import com.czq.common.utils.PageUtils;
import com.czq.common.utils.R;
import com.czq.gulimail.gulimailproduct.service.AttrService;
import com.czq.gulimail.gulimailproduct.vo.AttrEntityVO;
import com.czq.gulimail.gulimailproduct.vo.resp.AttrResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 商品属性
 *
 * @author czq
 * @email 1807099124@qq.com
 * @date 2024-09-23 19:03:06
 */
@RestController
@RequestMapping("gulimailproduct/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    /**
     * 获取分类下的销售属性
     */
    @RequestMapping("/sale/list/{catelogId}")
    public R sale(@RequestParam Map<String, Object> parmas, @PathVariable("catelogId") Long catelogId) {
        PageUtils page = attrService.querySalePage(parmas, catelogId);
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/{queryType}/list")
    public R list(@RequestParam Map<String, Object> params,
                  @PathVariable("queryType") String queryType) {
        PageUtils page = attrService.queryPage(params, queryType);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId) {
        AttrResp attr = attrService.getAttrRespById(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrEntityVO attr) {
        attrService.saveAttrEntityVO(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrEntityVO attr) {
        attrService.updateAttrEntityVO(attr);

        return R.ok();
    }

    /**
     * 修改是否可以检索
     */
    @RequestMapping("/updateSearchType")
    public R updateSearchType(@RequestParam Long attrId, @RequestParam Integer searchType) {

        attrService.updateSearchType(attrId, searchType);

        return R.ok();
    }

    @RequestMapping("/updateShowDesc")
    public R updateShowDesc(@RequestParam Long attrId, @RequestParam Integer showDesc) {

        attrService.updateShowDesc(attrId, showDesc);

        return R.ok();
    }

    @RequestMapping("/updateEnable")
    public R updateEnable(@RequestParam Long attrId, @RequestParam Integer enable) {

        attrService.updateEnable(attrId, enable);

        return R.ok();
    }

    @RequestMapping("/updateValueType")
    public R updateValueType(@RequestParam Long attrId, @RequestParam Integer valueType) {

        attrService.updateValueType(attrId, valueType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds) {
        attrService.removeAttrAndRelation(Arrays.asList(attrIds));

        return R.ok();
    }

}
